package linkedlist.reverse;

import linkedlist.Node;

/**
 * @Author wangtengyu
 * @Create 2018-09-03-14:48 递归反转链表
 */
public class RecursionReverse {


  public Node reverseLinkedList(Node head) {

    if (head == null || head.getNext() == null) {
      return head;//最后要把头结点返回来把
    }

    Node newHead = reverseLinkedList(head.getNext());
    head.getNext().setNext(head);
    head.setNext(null);

    return newHead;
  }

}
